package tech.jabari.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import tech.jabari.user.service.UserService;
import tech.jabari.user.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 删除用户
 */
@Controller
public class DelUserController {

    @Autowired
    private UserService userService ;

    /**
     * 单个删除用户
     * @param id
     * @return
     */
    @GetMapping("/{id}/delUser.action")
    @ResponseBody
    protected String delUser(@PathVariable Integer id) {
        //调用Service来删除用户
        int r = userService.delUser(id);
        if (r > 0) {
           return "OK";
        } else {
           return "NO";
        }
    }

    /**
     * 批量删除用户
     * @param delIds
     * @return
     */
    @RequestMapping("/batDelUser.action")
    protected String batchDeleteUser(String delIds)  {
        //调用Service来删除用户
        int r = userService.batchDelUser(delIds);
        if (r > 0) {
           return "OK";
        } else {
            return "NO";
        }
    }
}
